package com.lh.glorypavilion.service.aliyunvod.controller.api;


import com.lh.glorypavilion.exception.glorypavilionEx;
import com.lh.glorypavilion.result.R;
import com.lh.glorypavilion.result.ResultCode;
import com.lh.glorypavilion.service.aliyunvod.service.VideoService;
import com.lh.glorypavilion.util.ExceptionUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description="阿里云视频点播")
//@CrossOrigin //跨域
@RestController
@RequestMapping("/api/vod/media")
@Slf4j
public class ApiMediaController {

    @Autowired
    private VideoService videoService;

    @ApiOperation("获取视频凭证")
    @GetMapping("get-play-auth/{videoSourceId}")
    public R getPlayAuth(@ApiParam(value = "阿里云视频id",required = true)
                             @PathVariable("videoSourceId") String videoSourceId){
        try {
            String playAuth=videoService.getPlayAuth(videoSourceId);
            return R.ok().message("获取视频凭证成功！").data("playAuth",playAuth);
        }catch (Exception e){
            log.info(ExceptionUtils.getMessage(e));
            throw new glorypavilionEx(ResultCode.FETCH_PLAYAUTH_ERROR);
        }
    }
}
